// import Vue from 'vue'
// import Router from 'vue-router'  
import store from '../store/index.js'

Vue.use(VueRouter)

let test = {
  "en":{
      "index":"Home",
      "aboutus":"About us",
      "financing_one":"Financing plan/product approvement + collateral financing",
      "financing_two":"Financing plan/financing based on approval of the buyers",
      "overseas":"E-commerce services/Overseas warehouse",
      "duty_paragraph":"E-commerce services/German Tax Number Registration Service",
      "delivery":"E-commerce services/German e-commerce delivery service",
      "contact":"Contact us",
      "contact_form":"Contact us/Cooperation" 
    },
  "zh_cn":{
      "index":"首页",
      "aboutus":"关于我们",
      "financing_one":"融资方案/产品审核+货压",
      "financing_two":"融资方案/买家审核",
      "overseas":"电商服务/海外仓",
      "duty_paragraph":"电商服务/德国税号注册服务",
      "delivery":"电商服务/德国电商配送服务",
      "contact":"联系我们",
      "contact_form":"联系我们/合作" 
  }
}
 
const router = new VueRouter({
  routes: [
    // {
    //   path: '/',
    //   name: 'HelloWorld',
    //   component: HelloWorld
    // },
    {
      path: '/index',
      name: 'index',
      component: ()=>import("@/views/home"),
      meta:{
        title:'首页'
      }
    },
    {
      path: '/aboutus',
      name: 'aboutus',
      component: ()=>import("@/views/about"),
      meta:{
        title:'关于我们'
      }
    }, 
    {
      path: '/financing_case/1',
      name: 'financing_one',
      component: ()=>import("@/views/financing_one"),
      meta:{
        title:'融资方案/产品审核+货压'
        // title:test[store.state.language].financing_one//页面不刷新的时候，这个
      }
    },
    {
      path: '/financing_case/2',
      name: 'financing_two',
      component: ()=>import("@/views/financing_two"),
      meta:{
        title:'融资方案/买家审核'
      }
    },
    {
      path: '/eCommerce/overseas',
      name: 'overseas',
      component: ()=>import("@/views/overseas"),
      meta:{
        title:'电商服务/海外仓'
      }
    },
    {
      path: '/eCommerce/duty_paragraph',
      name: 'duty_paragraph',
      component: ()=>import("@/views/dutyParagraph"),
      meta:{
        title:'电商服务/德国税号注册服务'
      }
    },
    {
      path: '/eCommerce/delivery',
      name: 'delivery',
      component: ()=>import("@/views/delivery"),
      meta:{
        title:'电商服务/德国电商配送服务'
      }
    },
    {
      path: '/contact',
      name: 'contact',
      component: ()=>import("@/views/contact"),
      meta:{
        title:'联系我们'
      }
    },
    {
      path: '/contact_form',
      name: 'contact_form',
      component: ()=>import("@/views/contact_form"),
      meta:{
        title:'联系我们/合作'
      }
    },
  ]
})
 
/*路由拦截器设置-before*/
router.beforeEach((to, from, next) => { 
     if(to.path == '/'){
        next({path:'/index'})
       
      }
      else{
         next()
      }
});
router.afterEach((to,from,next) => {  
  let path = to.path 
  let pathArr = to.path.split('/')

  let testTitle = test[store.state.language]//language_choose
  let current = to.name//字段
  // let titleArr = to.meta.title.split('/')
  let titleArr = testTitle[current].split('/')
   
  let arr = [{path:'/index',title:testTitle.index}]
  if((path=='/index' || path=='/aboutus' || path=='/contact')){
    router.app.$store.commit("setbreadcrumbItems", []);
  }
  else{ 
      titleArr.forEach((item,index)=>{
        arr.push({path:'/'+pathArr[index+1],title:item,isRouter:false})
      })
      router.app.$store.commit("setbreadcrumbItems", arr);
  }
  // console.log(arr)
  
})
export default  router